#include "stdafx.h"
#include "Mesh.h"
#include "BufferManager.h"

using namespace Rendering;

/// <summary>Creates an index buffer and saves it into this object.</summary>
/// <param name="device">The direct3d device.</param>
/// <param name="indexCount">The number of indices for a mesh.</param>
/// <param name="indices">The indices.</param>
void Mesh::SetIndices(_In_ ID3D11Device *device, _In_ unsigned int indexCount,  _In_reads_(indexCount) unsigned short* indices)
{
	this->IndexCount = indexCount;
	if (indexCount > 0)
		BufferManager::CreateIndexBuffer(device, indexCount, indices, &m_indexBuffer);
}

/// <summary>Converts the RenderTopology to DirectX primitive topology.</summary>
/// <param name="renderTopology">The RenderTopology.</param>
/// <returns>The D3DPrimitiveTopology.<returns>
D3D_PRIMITIVE_TOPOLOGY Mesh::RenderToplogyToD3DPrimitiveTopology(RenderTopology renderTopology)
{
	switch (renderTopology)
	{
	case RenderTopology::TriangleList:
		return D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
	case RenderTopology::LineList:
		return D3D_PRIMITIVE_TOPOLOGY_LINELIST;
	case RenderTopology::TriangleStrip:
		return D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
	default:
		return D3D_PRIMITIVE_TOPOLOGY_UNDEFINED;
	}
}